import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service 采购员
 * @date: 2018-7-10


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
export function queryPurchaseAgent(_x) {
  return _queryPurchaseAgent.apply(this, arguments);
}
/**
 * 新增或更新采购员
 * @param {Object} params 新增或更新采购员参数
 */

function _queryPurchaseAgent() {
  _queryPurchaseAgent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.tenantId, "/purchases/agents"), {
              method: 'GET',
              query: query
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryPurchaseAgent.apply(this, arguments);
}

export function savePurchaseAgent(_x2) {
  return _savePurchaseAgent.apply(this, arguments);
}
/**
 * 获取用户列表
 * @param {Object} params 查询参数
 */

function _savePurchaseAgent() {
  _savePurchaseAgent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.tenantId, "/purchases/agents/batch-save"), {
              method: 'POST',
              body: params.list
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _savePurchaseAgent.apply(this, arguments);
}

export function fetchUserList() {
  return _fetchUserList.apply(this, arguments);
}
/**
 * 新建用户列表数据
 * @param {Object} params 查询参数
 */

function _fetchUserList() {
  _fetchUserList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var params,
        query,
        _args3 = arguments;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
            query = parseParameters(params);
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/purchases/agents/").concat(params.purchaseAgentId, "/assign-user"), {
              method: 'GET',
              query: query
            }));

          case 3:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _fetchUserList.apply(this, arguments);
}

export function updateUser() {
  return _updateUser.apply(this, arguments);
}
/**
 * 删除用户列表数据
 * @param {Object} params 查询参数
 */

function _updateUser() {
  _updateUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
    var params,
        _args4 = arguments;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            params = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/purchases/agents/assign-user"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateUser.apply(this, arguments);
}

export function deleteUser() {
  return _deleteUser.apply(this, arguments);
}

function _deleteUser() {
  _deleteUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var params,
        _args5 = arguments;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/purchases/agents/assign-user"), {
              method: 'DELETE',
              body: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteUser.apply(this, arguments);
}